<template>
	<view class="Recharge_content Transfer_content">
		<view class="kuang">
			<view class="title">
				<view class="inline-block left">
					<image src="../../static/image/left.png" mode="" @tap="back"></image>
				</view>
			</view>
			<view class="vote_title">
				<image src="../../static/image/wallet_icon.png"></image>
				<text>{{i18n.vote_title}}</text>
			</view>
			<view class="candidate">
				<text>{{i18n.candidatezc}}</text>
				<!-- <image src="../../static/image/list.png" @tap="coin_manage"></image> -->
			</view>
			<scroll-view scroll-y="true" class="data_list"
			@scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll"
			>
				<view v-if="assetsList.length > 0">
					<view class="item" @tap="coin_detail(item.assetId,item.symbol,item.balance,item.decimals,item.assetName)"
					v-for="(item,index) in assetsList"
					:key="index"
					v-if="item.isShow"
					>
						<view class="item_detail">
							<view class="detail_left">
								<image v-if="item.assetId==0"  src="../../static/image/icon_detail.png"></image>
								<image  v-else src="../../static/image/greylogo.png"></image>
								<view class="left_right">
									<view>{{ getUpCase(item.symbol) }}</view>
								</view>
							</view>
							<view class="left_right">
								<view>{{getAmount(item.balance,item.decimals)}}</view>
							</view>
						</view>
					</view>
				</view>
				<view v-show="isnoData" class="nodata">
					{{i18n.wzc}}
				</view>
				
				
			</scroll-view>
			
		</view>


	</view>
</template>

<script>
	import * as oex from 'oex-web3'; 
	import account from '../../common/account.js'
	//import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import {myMixins} from '../../common/mixins.js'
	export default {
		computed: {
			i18n() {
				return this.$t('user')
			}
		},
		mixins: [myMixins], // 使用mixin
		data() {
			return {
				//个人账户信息
				accountName:"",
				accountID:"",
				balances:[],
				dataArr:[],
				isnoData:false,
				limit:[],
				assetsList:[]
			}
		},
		onLoad() {
			//获取个人账户信息
			uni.showLoading();
			this.getAccountExByName();
		},
		methods: {
			getUpCase(symbol){
				return symbol.toUpperCase()
			},
			getAccountExByName(){
				//加载资产列表
				const _this = this;
				account.getAccount(this.account_info.accountName).then(res =>{
					//console.log(res)
					_this.balances = res.data.result.balances;
					if(res.data.result.balances.length > 0){
						_this.getInfoByAssetsID(res.data.result.balances);
					}else{
						uni.hideLoading()
						_this.isnoData = true;
					}
					
					
				}).catch(error =>{
					uni.hideLoading()
					_this.$CommonJS.showToast(_this._i18n.locale == 'zh_CN' ? '请求超时':'Request Timeout',)
				})
			},
			
			getInfoByAssetsID(data){
				//查看币种
				
				if(data.length<1){
					uni.hideLoading()
					this.isnoData = true;
					return;
				}
				const _this = this;
				const nodeInfo = uni.getStorageSync('nodeInfo');
				 data.map(item =>{
					
					  account.getCoin(nodeInfo,item.assetID).then(result =>{
						result.data.result.isShow = true;
						result.data.result.balance = item.balance
						  _this.assetsList. unshift(result.data.result)
						uni.hideLoading()
					})
				})
			},
			getAmount(amount,decimals){
				//转换数量
				return amount/Math.pow(10,decimals)
			},
			getCoinIcon(assetID){
				return 'http://oexchain.io/asset/'+ assetID +'/logo.png'
			},
			coin_detail(assetId,symbol,amount,decimals,assetName){
				//币种详情
				
				const _amount = this.getAmount(amount,decimals);
				this.$CommonJS.navigateTo('./coin_detail?assetId='+ assetId + '&symbol=' + symbol + '&amount='+ _amount + '&decimals=' + decimals + '&assetName=' + assetName)
			},
			back(){
				this.$CommonJS.navigateBack()
			},
			upper: function(e) {
			},
			lower: function(e) {
			},
			scroll: function(e) {
					//this.old.scrollTop = e.detail.scrollTop
			},
			coin_manage(){
				if(this.balances.length < 1){
					return;
				}
				const _this = this;
				//return;
			//	this.$store.commit('setAssetsList',this.dataArr);
				this.$CommonJS.navigateTo('./coin_manage')
				
				// uni.removeStorage({
				//     key: 'assetsList',
				//     success: function (res) {
				//         uni.setStorage({
				//         	key:"assetsList",
				//         	data:_this.dataArr,
				//         	success() {
				//         		_this.$CommonJS.navigateTo('./coin_manage')
				//         	}
				//         })
				//     }
				// });
				uni.setStorage({
					key:"assetsList",
					data:_this.assetsList,
					success() {
						_this.$CommonJS.navigateTo('./coin_manage')
					}
				})
				//this.$CommonJS.navigateTo('./coin_manage')
			}
		}
	}
</script>

<style lang="stylus">
	@import "../../static/stylus/wallet/wallet.stylus"
	.nodata 
		font-size 13px 
		color #c2c9df
		width 100%
		height 100%
		display flex
		flex-direction column
		justify-content center
		align-items center
</style>
